package com.ruoyi.web.controller.model.controller;

import java.util.List;

import com.ruoyi.system.recovery.domain.RecoveryService;
import com.ruoyi.system.recovery.domain.vo.RecoveryServiceVo;
import com.ruoyi.system.recovery.service.IRecoveryServiceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 售后Controller
 *
 * @author ruoyi
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/recovery/service")
public class RecoveryServiceController extends BaseController {
    @Autowired
    private IRecoveryServiceService recoveryServiceService;

    /**
     * 查询售后列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecoveryService recoveryService) {
        startPage();
        List<RecoveryServiceVo> list = recoveryServiceService.selectRecoveryServiceList(recoveryService);
        return getDataTable(list);
    }

    /**
     * 导出售后列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:service:export')")
    @Log(title = "售后", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RecoveryService recoveryService) {
        List<RecoveryServiceVo> list = recoveryServiceService.selectRecoveryServiceList(recoveryService);
        ExcelUtil<RecoveryServiceVo> util = new ExcelUtil<RecoveryServiceVo>(RecoveryServiceVo.class);
        return util.exportExcel(list, "售后数据");
    }

    /**
     * 获取售后详细信息
     */
    @PreAuthorize("@ss.hasPermi('recovery:service:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(recoveryServiceService.selectRecoveryServiceById(id));
    }

    /**
     * 新增售后
     */
    @PreAuthorize("@ss.hasPermi('recovery:service:add')")
    @Log(title = "售后", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecoveryService recoveryService) {
        return toAjax(recoveryServiceService.insertRecoveryService(recoveryService));
    }

    /**
     * 修改售后
     */
    @PreAuthorize("@ss.hasPermi('recovery:service:edit')")
    @Log(title = "售后", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecoveryService recoveryService) {
        return toAjax(recoveryServiceService.updateRecoveryService(recoveryService));
    }

    /**
     * 删除售后
     */
    @PreAuthorize("@ss.hasPermi('recovery:service:remove')")
    @Log(title = "售后", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(recoveryServiceService.deleteRecoveryServiceByIds(ids));
    }

    /**
     * 处理售后
     */
    @PreAuthorize("@ss.hasPermi('recovery:service:edit')")
    @Log(title = "处理售后", businessType = BusinessType.UPDATE, businessId = "#recoveryService.recoveryInfoId")
    @PutMapping("/handleService")
    public AjaxResult handleService(@RequestBody RecoveryService recoveryService) {
        return toAjax(recoveryServiceService.handleService(recoveryService));
    }

    /**
     * 取消售后
     */
    @PreAuthorize("@ss.hasPermi('recovery:service:edit')")
    @Log(title = "取消售后", businessType = BusinessType.UPDATE, businessId = "#recoveryService.recoveryInfoId")
    @PutMapping("/cancelService")
    public AjaxResult cancelService(@RequestBody RecoveryService recoveryService) {
        return toAjax(recoveryServiceService.cancelService(recoveryService));
    }

    /**
     * 完结售后
     */
    @PreAuthorize("@ss.hasPermi('recovery:service:edit')")
    @Log(title = "完结售后", businessType = BusinessType.UPDATE, businessId = "#recoveryService.recoveryInfoId")
    @PutMapping("/endService")
    public AjaxResult endService(@RequestBody RecoveryService recoveryService) {
        return recoveryServiceService.endService(recoveryService);
    }




}
